﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Traversing - Filtering</title>
    <script src="script/jquery-1.3.2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $("button").click(colorEm);
        });

        function colorEm() {
            var $div = $("div");
            var start = Math.floor(Math.random() *
                             $div.length);
            var end = Math.floor(Math.random() *
                           ($div.length - start)) +
                           start + 1;
            if (end == $div.length) end = undefined;
            $div.css("background", "");
            if (end)
                $div.slice(start, end).css("background", "yellow");
            else
                $div.slice(start).css("background", "yellow");

            $("span").text('$("div").slice(' + start +
                     (end ? ', ' + end : '') +
                     ').css("background", "yellow");');
        } 

    </script>
    <style type="text/css">
    div
    {
        border:solid 1px #000;
        height:30px;
        width:113px;
        margin:13px;
    }
    </style>
</head>
<body>
    <button>Turn slice yellow</button> 
    <span>Click the button!</span> 
    <div></div> 
    <div></div> 

    <div></div> 
    <div></div> 
    <div></div> 
    <div></div> 
    <div></div> 

    <div></div> 
    <div></div>
</body>
</html>
